import { defHttp } from '/@/utils/http/axios';
import { useMessage } from '/@/hooks/web/useMessage';

const { createConfirm } = useMessage();

enum Api {
  list = '/entrust/labEntrust/list',
  save = '/entrust/labEntrust/add',
  edit = '/entrust/labEntrust/edit',
  deleteOne = '/entrust/labEntrust/delete',
  deleteBatch = '/entrust/labEntrust/deleteBatch',
  importExcel = '/entrust/labEntrust/importExcel',
  exportXls = '/entrust/labEntrust/exportXls',
  queryDataById = '/entrust/labEntrust/queryById',
  submitFirstEnt = '/entrust/labEntrust/submitFirstEnt',
  cancelOneEnt = '/entrust/labEntrust/cancelOneEnt',
  auditPass = '/entrust/labEntrust/auditPass',
  auditBack = '/entrust/labEntrust/auditBack',
  labSampleList = '/entrust/labEntrust/queryLabSampleListByEntId',
  labSortsList = '/items/labItems/queryByPid',
  labSampleLists = '/entrust/labEntrust/queryLabSampleByMainId',
  samCodeSerialNum = '/entrust/labEntrust/SamCodeSerialNum',
  downloadExcel = '/entrust/labEntrust/downloadExcel',
  operList = '/operation/labOperation/list',
  signature = '/entrust/labEntrust/signature',
  servestoken = '/entrust/labEntrust/serveToken',
  auditList = '/entrust/labEntrust/auditList',
  judgeHasSign = '/entrust/labEntrust/byuserIdif', // 判断当前账号是否已有电子签名
  getAduitSign = '/entrust/labEntrust/byIdsa', // 获取初审、复审人员签名
  getExperimentProjectsList = '/items/labItems/queryItemsByPid', // 获取实验数据
}
/**
 * 导出api
 * @param params
 */
export const getExportUrl = Api.exportXls;

/**
 * 导入api
 */
export const getImportUrl = Api.importExcel;
/**
 * 签名url地址转存数据库
 */
export const signature2 = Api.signature;
/**
 * 下载模板
 * @param params
 */
export const downloadExcel = Api.downloadExcel;

/**
 * 列表接口
 * @param params
 */
export const list = (params) => defHttp.get({ url: Api.list, params });

/**
 * 删除单个
 */
export const deleteOne = (params, handleSuccess) => {
  return defHttp.delete({ url: Api.deleteOne, params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess();
  });
};
/**
 * 批量删除
 * @param params
 */
export const batchDelete = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({ url: Api.deleteBatch, data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess();
      });
    },
  });
};
/**
 * 保存或者更新
 * @param params
 */
export const saveOrUpdate = (params, isUpdate) => {
  let url = isUpdate ? Api.edit : Api.save;
  return defHttp.post({ url: url, params });
};

/**
 * 提交发布单
 * 用delete能实现功能但表示不好  后续优化
 */
export const submitOneEnt = (params, handleSuccess) => {
  return defHttp.delete({ url: Api.submitFirstEnt, params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess();
  });
};

/**
 * 撤销发布单
 * 用delete能实现功能但不是很好  后续优化
 */
export const cancelOneEnt = (params, handleSuccess) => {
  return defHttp.delete({ url: Api.cancelOneEnt, params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess();
  });
};

/**
 * 初审、复审通过前先判断为否有电子签章
 */
export const judgeHasSign = (params) => defHttp.get({ url: Api.judgeHasSign, params }, { isTransformResponse: false });

/**
 * 获取初审、复审人员签名
 */
export const getAduitSign = (params) => defHttp.get({ url: Api.getAduitSign, params }, { isTransformResponse: false });

/**
 * 初审/复审通过
 * @param params
 */
export const auditPass = (params) => {
  let url = Api.auditPass;
  return defHttp.post({ url: url, params });
};

/**
 * 初审/复审退回
 * @param params
 */
export const auditBack = (params) => {
  let url = Api.auditBack;
  return defHttp.post({ url: url, params });
};

/**
 * 根据id查询数据
 * @param params
 */
export const queryDataById = (id) => defHttp.get({ url: Api.queryDataById, params: { id } });

/**
 * 子表单信息
 * @param params
 */
export const labSampleList = (params) => defHttp.get({ url: Api.labSampleList, params });

/**
 * 获取样品类型
 * @param params
 */
export const labSortsList = (params) => defHttp.get({ url: Api.labSortsList, params });

/**
 * 根据委托单查样品信息
 * @param params
 */
export const queryLabSample = Api.labSampleLists;

/**
 * 样品列表接口
 * @param params
 */
export const labSampleLists = (params) => defHttp.get({ url: Api.labSampleLists, params }, { isTransformResponse: false });

/**
 * 样品编号接口
 * @param params
 */
export const samCodeSerialNum = (params) => defHttp.get({ url: Api.samCodeSerialNum, params });

/**
 * 修改记录列表接口
 * @param params
 */
export const operList = (params) => defHttp.get({ url: Api.operList, params });
/**
 * 签名url地址转存数据库
 */
//export const signature = (params) => defHttp.post({ url: Api.signature, params });
export const signature = Api.signature;
/**
 * 获取服务token和员工票据
 */
//export const servestoken = (params) => defHttp.get({ url: Api.servestoken, params });
export const servestoken = Api.servestoken;
/**
 * 列表接口
 * @param params
 */
export const auditList = (params) => defHttp.get({ url: Api.auditList, params });

/**
 * 获取实验项目数据
 */
export const getExperimentProjects = (params) => defHttp.get({ url: Api.getExperimentProjectsList, params }, { isTransformResponse: false });

